﻿// =================================================================== 
// 项目说明
//====================================================================
// Wup。@Copy Right 2014
// 文件： reAsk.cs
// 项目名称：买车网
// 创建时间：2014/7/20
// 负责人：Wup
// ===================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Weixin.Entity.ChinaTax;
using Weixin.Utils;


namespace Weixin.DAL.ChinaTax
{
    /// <summary>
    /// 数据层实例化接口类 dbo.reAsk.
    /// </summary>
    public partial class reAskDataAccessLayer 
    {
		#region 构造函数


		/// <summary>
		/// 
		/// </summary>
		public reAskDataAccessLayer()
		{
		}
		#endregion

        #region -----------实例化接口函数-----------
		
		#region 添加更新删除
		/// <summary>
		/// 向数据库中插入一条新记录。
		/// </summary>
		/// <param name="_reAskModel">reAsk实体</param>
		/// <returns>新插入记录的编号</returns>
		public int Insert(reAskEntity _reAskModel)
		{
			string sqlStr="insert into reAsk([askID],[content],[good],[flag],[utime],[username]) values(@askID,@content,@good,@flag,@utime,@username) select @@identity";
			int res;
			SqlParameter[] _param={
			new SqlParameter("@askID",SqlDbType.Int),
			new SqlParameter("@content",SqlDbType.VarChar),
			new SqlParameter("@good",SqlDbType.Int),
			new SqlParameter("@flag",SqlDbType.Int),
			new SqlParameter("@utime",SqlDbType.DateTime),
			new SqlParameter("@username",SqlDbType.VarChar)
			};			
			_param[0].Value=_reAskModel.askID;
			_param[1].Value=_reAskModel.content;
			_param[2].Value=_reAskModel.good;
			_param[3].Value=_reAskModel.flag;
			_param[4].Value=_reAskModel.utime;
			_param[5].Value=_reAskModel.username;
			res = Convert.ToInt32(SqlHelper.ExecuteScalar(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param));
			return res;
		}
		/// <summary>
		/// 向数据库中插入一条新记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_reAskModel">reAsk实体</param>
		/// <returns>新插入记录的编号</returns>
		public int Insert(SqlTransaction sp,reAskEntity _reAskModel)
		{
			string sqlStr="insert into reAsk([askID],[content],[good],[flag],[utime],[username]) values(@askID,@content,@good,@flag,@utime,@username) select @@identity";
			int res;
			SqlParameter[] _param={
			new SqlParameter("@askID",SqlDbType.Int),
			new SqlParameter("@content",SqlDbType.VarChar),
			new SqlParameter("@good",SqlDbType.Int),
			new SqlParameter("@flag",SqlDbType.Int),
			new SqlParameter("@utime",SqlDbType.DateTime),
			new SqlParameter("@username",SqlDbType.VarChar)
			};			
			_param[0].Value=_reAskModel.askID;
			_param[1].Value=_reAskModel.content;
			_param[2].Value=_reAskModel.good;
			_param[3].Value=_reAskModel.flag;
			_param[4].Value=_reAskModel.utime;
			_param[5].Value=_reAskModel.username;
			res = Convert.ToInt32(SqlHelper.ExecuteScalar(sp,CommandType.Text,sqlStr,_param));
			return res;
		}


		/// <summary>
		/// 向数据表reAsk更新一条记录。
		/// </summary>
		/// <param name="_reAskModel">_reAskModel</param>
		/// <returns>影响的行数</returns>
		public int Update(reAskEntity _reAskModel)
		{
            string sqlStr="update reAsk set [askID]=@askID,[content]=@content,[good]=@good,[flag]=@flag,[utime]=@utime,[username]=@username where ID=@ID";
			SqlParameter[] _param={				
				new SqlParameter("@ID",SqlDbType.Int),
				new SqlParameter("@askID",SqlDbType.Int),
				new SqlParameter("@content",SqlDbType.VarChar),
				new SqlParameter("@good",SqlDbType.Int),
				new SqlParameter("@flag",SqlDbType.Int),
				new SqlParameter("@utime",SqlDbType.DateTime),
				new SqlParameter("@username",SqlDbType.VarChar)
				};				
				_param[0].Value=_reAskModel.ID;
				_param[1].Value=_reAskModel.askID;
				_param[2].Value=_reAskModel.content;
				_param[3].Value=_reAskModel.good;
				_param[4].Value=_reAskModel.flag;
				_param[5].Value=_reAskModel.utime;
				_param[6].Value=_reAskModel.username;
			return SqlHelper.ExecuteNonQuery(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param);
		}
		/// <summary>
		/// 向数据表reAsk更新一条记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_reAskModel">_reAskModel</param>
		/// <returns>影响的行数</returns>
		public int Update(SqlTransaction sp,reAskEntity _reAskModel)
		{
            string sqlStr="update reAsk set [askID]=@askID,[content]=@content,[good]=@good,[flag]=@flag,[utime]=@utime,[username]=@username where ID=@ID";
			SqlParameter[] _param={				
				new SqlParameter("@ID",SqlDbType.Int),
				new SqlParameter("@askID",SqlDbType.Int),
				new SqlParameter("@content",SqlDbType.VarChar),
				new SqlParameter("@good",SqlDbType.Int),
				new SqlParameter("@flag",SqlDbType.Int),
				new SqlParameter("@utime",SqlDbType.DateTime),
				new SqlParameter("@username",SqlDbType.VarChar)
				};				
				_param[0].Value=_reAskModel.ID;
				_param[1].Value=_reAskModel.askID;
				_param[2].Value=_reAskModel.content;
				_param[3].Value=_reAskModel.good;
				_param[4].Value=_reAskModel.flag;
				_param[5].Value=_reAskModel.utime;
				_param[6].Value=_reAskModel.username;
			return SqlHelper.ExecuteNonQuery(sp,CommandType.Text,sqlStr,_param);
		}		
		
		
		/// <summary>
		/// 删除数据表reAsk中的一条记录
		/// </summary>
	    /// <param name="ID">iD</param>
		/// <returns>影响的行数</returns>
		public int Delete(int ID)
		{
			string sqlStr="delete from reAsk where [ID]=@ID";
			SqlParameter[] _param={			
			new SqlParameter("@ID",SqlDbType.Int),
			
			};			
			_param[0].Value=ID;
			return SqlHelper.ExecuteNonQuery(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param);
		}
		
		/// <summary>
		/// 删除数据表reAsk中的一条记录,带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
	    /// <param name="ID">iD</param>
		/// <returns>影响的行数</returns>
		public int Delete(SqlTransaction sp,int ID)
		{
			string sqlStr="delete from reAsk where [ID]=@ID";
			SqlParameter[] _param={			
			new SqlParameter("@ID",SqlDbType.Int),
			
			};			
			_param[0].Value=ID;
			return SqlHelper.ExecuteNonQuery(sp,CommandType.Text,sqlStr,_param);
		}
		#endregion
		
		#region 数据实体
		/// <summary>
		/// 得到  reask 数据实体
		/// </summary>
		/// <param name="row">row</param>
		/// <returns>reask 数据实体</returns>
		public reAskEntity Populate_reAskEntity_FromDr(DataRow row)
		{
			reAskEntity Obj = new reAskEntity();
			if(row!=null)
			{
				Obj.ID = (( row["ID"])==DBNull.Value)?0:Convert.ToInt32( row["ID"]);
				Obj.askID = (( row["askID"])==DBNull.Value)?0:Convert.ToInt32( row["askID"]);
				Obj.content =  row["content"].ToString();
				Obj.good = (( row["good"])==DBNull.Value)?0:Convert.ToInt32( row["good"]);
				Obj.flag = (( row["flag"])==DBNull.Value)?0:Convert.ToInt32( row["flag"]);
				Obj.utime = (( row["utime"])==DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime( row["utime"]);
				Obj.username =  row["username"].ToString();
			}
			else
			{
				return null;
			}
			return Obj;
		}
		
        /// <summary>
		/// 得到  reask 数据实体
		/// </summary>
		/// <param name="dr">dr</param>
		/// <returns>reask 数据实体</returns>
		public reAskEntity Populate_reAskEntity_FromDr(IDataReader dr)
		{
			reAskEntity Obj = new reAskEntity();
			
				Obj.ID = (( dr["ID"])==DBNull.Value)?0:Convert.ToInt32( dr["ID"]);
				Obj.askID = (( dr["askID"])==DBNull.Value)?0:Convert.ToInt32( dr["askID"]);
				Obj.content =  dr["content"].ToString();
				Obj.good = (( dr["good"])==DBNull.Value)?0:Convert.ToInt32( dr["good"]);
				Obj.flag = (( dr["flag"])==DBNull.Value)?0:Convert.ToInt32( dr["flag"]);
				Obj.utime = (( dr["utime"])==DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime( dr["utime"]);
				Obj.username =  dr["username"].ToString();
			
			return Obj;
		}
		#endregion
		
		/// <summary>
		/// 根据ID,返回一个reAsk对象
		/// </summary>
		/// <param name="iD">iD</param>
		/// <returns>reAsk对象</returns>
		public reAskEntity Get_reAskEntity (int iD)
		{
			reAskEntity _obj=null;
			SqlParameter[] _param={
			new SqlParameter("@ID",SqlDbType.Int)
			};
			_param[0].Value=iD;
			string sqlStr="select * from reAsk with(nolock) where ID=@ID";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param))
			{
				while(dr.Read())
				{
            		_obj=Populate_reAskEntity_FromDr(dr);
				}
			}
			return _obj;
		}
		/// <summary>
		/// 得到数据表reAsk所有记录
		/// </summary>
		/// <returns>数据集</returns>
		public IList< reAskEntity> Get_reAskAll()
		{
			IList< reAskEntity> Obj=new List< reAskEntity>();
			string sqlStr="select * from reAsk";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(WebConfig.ChinaTax,CommandType.Text,sqlStr))
			{
				while(dr.Read())
				{
					Obj.Add(Populate_reAskEntity_FromDr(dr));
				}
			}
			return Obj;
		}
		/// <summary>
        /// 检测是否存在根据主键
        /// </summary>
        /// <param name="iD">iD</param>
        /// <returns>是/否</returns>
		public bool IsExistreAsk(int iD)
		{
			SqlParameter[] _param={
                                      new SqlParameter("@iD",SqlDbType.Int)
                                  };
            _param[0].Value=iD;
            string sqlStr="select Count(*) from reAsk where ID=@iD";
            int a=Convert.ToInt32(SqlHelper.ExecuteScalar(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param));
            if(a>0)
            {
                return true;
            }
            else
            {
                return false;
            }
		}

        #endregion
		
		#region----------自定义实例化接口函数----------
		#endregion
    }
}
